﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using LinqExpression = System.Linq.Expressions.Expression;

namespace SimpleData.Infrastructure.JavaScript
{
	/// <summary>
	/// Representa um símbolo
	/// </summary>
	public class ExpressionSymbol
	{
		internal ExpressionSymbol( string name, SymbolKind kind, SymbolTable table )
		{
			this.Name = name;
			this.Kind = kind;
			this.Table = table;
			this.Parameters = new List<ParameterExpression>();
		}

		public LinqExpression Expression
		{ get; set; }

		public string Name
		{ get; private set; }

		public SymbolKind Kind
		{ get; private set; }

		public List<ParameterExpression> Parameters
		{ get; private set; }

		public SymbolTable Table
		{ get; private set; }

		public ExpressionSymbol DeclareParameter( ParameterExpression param )
		{
			string name = param.Name;
			var symbol = this.Table.Declare( name, SymbolKind.Parameter );
			symbol.Expression = param;
			this.Parameters.Add( param );
			return symbol;
		}
	}
}
